home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.teleport.com!usenet
- From: GHouck <hksys@teleport.com>
- Newsgroups: comp.lang.c
- Subject: Re: returning address of value to main
- Date: 12 Apr 1996 03:36:35 GMT
- Organization: systems hk
- Message-ID: <4kkj43$c32@nadine.teleport.com>
- References: <4khpjq$a3c@pipe1.nyc.pipeline.com>
- NNTP-Posting-Host: ip-pdx08-22.teleport.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
-
- luciferm@nyc.pipeline.com (manjila thapa) wrote:
- >I want to return the address of element of an array
- >a[0]....a[n]....a[m-1] (address of a[n] is to be returned)
- >from a function to the main so that:
- >
- >main(){
- >double *newarr;
- >...
- >...
- >newarr= function(......) /*function is supposed to return address*/
- >__________________________________________
- >i tried
- >
- >return &a[n];
- >
- >in function but it doesn't work! Isn't this the right way to get the
- >address? (this is part of my hw, hope u don't mind)
-
- Manny,
- It should work if array 'a' is not local to the function, since the
- address you return from the function would point to an undefined
- location once the function returns. 'a' would have to be global or
- at least local to the calling routine and passed to the function, e.g.:
-
- double a[100];
- double *newarr;
- double *function ( double a[] );
-
- ..
- newarr = function( a );
- ..
-
-
- double *function ( double a[] )
- {
- ...
- return( &a[5] );
- }
-
- Yours, Geoff
-
-